package com.loopy.cookie;

import javax.servlet.http.Cookie;

public class CookieUtils {
    public static Cookie readCookieByName(String name,Cookie[] cookies){
        if(name==null||"".equals(name)||cookies==null||cookies.length==0){
            return  null;
        }

        for (Cookie cookie : cookies) {
            if(name.equals(cookie.getName())){
                return cookie;
            }
        }
        return null;
    }
    public static Cookie updateCookie(String name,Cookie[] cookies){
        if(null!=readCookieByName(name,cookies)){
            Cookie cookie = readCookieByName(name, cookies);
            cookie.setValue("hsp-hi");
            return cookie;
        }else{
            System.out.println("当前访问服务端浏览器没有该cookie");
        }
        return null;
    }

}
